package TUILayer;
import java.util.Scanner;
import java.util.ArrayList;
import ControlLayer.DVDCtr;
import ModelLayer.*;

/**
 * User interface to the DVD controller
 * @author(kbh)
 * @version(2005.03.31)
 * (FEN): 2006.02.24: Comments translated into English
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 * (KBH): 2008.10.24: dvdmenu changed to If 
 * (KBH): 2010.04.09: Changed som comments
 */

public class DvdUI
{
    private DVDCtr _dvdCtr;//DVD UI must know the DVD controller 
    
    public DvdUI()
    {
        _dvdCtr = new DVDCtr();
    }
    
    public void start()
    {
        
        dvdMenu();
    }
    
    public void dvdMenu()
    {   
        boolean exit = false;
        while(!exit)
        {
            //show menu and return the user's choise
            int choise =   writeDVDMenu();
            if (choise == 1)
            {
                findDVD();
            }
            else{if(choise == 2){
                   createDVD();
                }
                else{
                    if(choise == 3){
                        createCopy();
                    }
                    else{
                        if(choise == 4){
                             deleteDVD();
                        }
                        else{
                            if(choise == 5){
                                listAllDvds();
                            }
                            else{
                                exit = true;
                            }//end else
                        }//end else
                    }//end else
                }//end else
            }//end else
            
        }//end while
    }
    private int writeDVDMenu()
    {
           // creates an object keyboard to read data from the keyboard
            Scanner keyboard = new Scanner(System.in);
            System.out.println("\f *** DVD Menu ***");
            System.out.println(" (1) Show DVD information");
            System.out.println(" (2) Create DVD description");
            System.out.println(" (3) Create DVD specimen");
            System.out.println(" (4) Delete DVD");
            System.out.println(" (5) Show current DVD list");
            System.out.println(" (6) Return");
            System.out.print("\n Make your choise: ");
            
            int choise = keyboard.nextInt();
            
            return choise;
    }
    private long inputDVDNo()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD number: ");
        long no = keyboard.nextInt();
        return no;
    }
        
    private String inputTitle()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type DVD title: " );
        String title = keyboard.nextLine();
        return title;
    }
    
    private String inputDirector()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type Director name: ");
        String director = keyboard.nextLine();
        return director;
    }
    
    private String inputReleaseDate()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type release date: ");
        String releaseDate = keyboard.nextLine();
        return releaseDate;
    }
    
    private int inputCopyNo()
    {
        // creates an object keyboard to read data from the keyboard
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type the copy number: ");
        int no = keyboard.nextInt();
        return no;
    }
    
    private long inputDvdID()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type dvd id: ");
        long inputDvdID = keyboard.nextLong();
        return inputDvdID;
    }
    
    private String inputSerialNr()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type serial number: ");
        String inputSerialNr = keyboard.nextLine();
        return inputSerialNr;
    }
    
    private String inputObtainDate()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type obtain date: ");
        String inputObtainDate = keyboard.nextLine();
        return inputObtainDate;
    }
    
    private String inputObtainPrice()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("Type obtain price: ");
        String inputObtainPrice = keyboard.nextLine();
        return inputObtainPrice;
    }
    
    //there is need for more methods to read information about DVDs
    //and methods to display the information
  
    private void findDVD()
    {     
        try
        {
            long id = inputDVDNo();
            
            
            String dvd = _dvdCtr.findDVD(id);
            System.out.println("\f" + dvd);
            
        }
        catch(Exception e)
        {
            System.out.println("The DVD you are trying to find does not exist");
        }
    
        System.out.print("\nPress " + "1 " + "to show menu: ");
        MainMenuUI.pause();
    }
    
    private void createDVD()
    {
        long id = inputDVDNo();
        String title = inputTitle();
        String director = inputDirector();
        String releaseDate = inputReleaseDate();
        
        _dvdCtr.createDVD(id, title, director, releaseDate);
    }
    private void createCopy()
    {
        long dvdID = inputDvdID();
        String serialNr = inputSerialNr();
        String obtainDate = inputObtainDate();
        String obtainPrice = inputObtainPrice();
        
        _dvdCtr.createCopy(dvdID, serialNr, obtainDate, obtainPrice);
    }
    
    private void deleteDVD()
    {

                try
        {
            long id = inputDVDNo();
            
            
            _dvdCtr.deleteDVD(id);
            System.out.println("\f" + id);
            
        }
        catch(Exception e)
        {
            System.out.println("The DVD you are trying to delete does not exist");
        }
    }
    private void listAllDvds()
    {
        String dvds = _dvdCtr.listAllDvds();
        
        System.out.println("\f" + dvds);
        System.out.print("Press " + "1 " + "to show menu: ");
        MainMenuUI.pause();
    }
}